// Created by WXX on 2022/2/4 11:24
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

/**
 * 执行用时：52 ms, 在所有 C++ 提交中击败了13.76%的用户
 * 内存消耗：19.8 MB, 在所有 C++ 提交中击败了8.26%的用户
 */
class Solution {
public:
    int countGoodRectangles(vector<vector<int>>& rectangles) {
        unordered_map<int, int> cnt;
        int res = 0, maxv = 0;
        for (auto r : rectangles) {
            int t = min(r[0], r[1]);
            if (t >= maxv) {
                maxv = t;
                res = cnt[t] + 1;
            }
            cnt[t]++;
        }
        return res;
    }
};

int main() {

    vector<vector<int>> rectangles = {
            {5, 8},
            {3, 9},
            {5, 12},
            {16, 5},
    };
    cout << Solution().countGoodRectangles(rectangles) << endl;  // 3

    return 0;
}
